home *** CD-ROM | disk | FTP | other *** search
- #include "Sample.h" /* bring in all the #defines for Sample */
- #include "SampleDefs.h"
- #include "SampleAEvt.h"
- #include "SampleFileIO.h"
- #include "SamplePrint.h"
- #include "SampleErrors.h"
- #include "SampleMain.h"
-
- #include <Resources.h>
- #include <Fonts.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <Desk.h>
- #include <ToolUtils.h>
- #include <Memory.h>
- #include <OSEvents.h>
- #include <DiskInit.h>
- #include <Traps.h>
- #include <Errors.h>
-
- SysEnvRec gMac; /* set up by Initialize */
- Boolean gHasWaitNextEvent; /* set up by Initialize */
- Boolean gInBackground = false; /* maintained by DoEvent */
- Rect gStopRect; /* set up by Initialize */
- Rect gGoRect; /* set up by Initialize */
- THPrint gPrRecHdl;
- Str255 gTitle;
- Boolean gQuit = false;
- Boolean gHasPPCToolbox = false;
- Boolean gHasAppleEvents = false;
- Boolean gSendToSelf = true;
- Boolean gHasNewStdFile = false;
- WindowData gWindowData;
- short gReplyMode = kAENoReply;
- RgnHandle gCursorRgn;
-
- Boolean gDefaultOK = false;
- LocationNameRec gLocation;
- PortInfoRec gPortInfo;
-
-
- /* Define HiWrd and LoWrd macros for efficiency. */
- #define HiWrd(aLong) (((aLong) >> 16) & 0xFFFF)
- #define LoWrd(aLong) ((aLong) & 0xFFFF)
-
- /* Define TopLeft and BotRight macros for convenience. Notice the implicit
- dependency on the ordering of fields within a Rect */
- #define TopLeft(aRect) (* (Point *) &(aRect).top)
- #define BotRight(aRect) (* (Point *) &(aRect).bottom)
-
-
- /* This routine is part of the MPW runtime library. This external
- reference to it is done so that we can unload its segment, %A5Init. */
-
- extern void _DataInit();
-
-
- #pragma segment Main
- main()
- {
- MaxApplZone();
- Initialize(); /* initialize the program */
- // StartDocuments(); /* open any documents if requested */
-
- EventLoop(); /* call the main event loop */
- }
-
-
- /* Get events forever, and handle them by calling DoEvent.
- Get the events by calling WaitNextEvent, if it's available, otherwise
- by calling GetNextEvent. Also call AdjustCursor each time through the loop. */
-
- #pragma segment Main
- void EventLoop()
- {
- Boolean gotEvent;
- EventRecord event;
- Point mouse;
-
- gCursorRgn = NewRgn(); /* we’ll pass WNE an empty region the 1st time thru */
- do {
- /* use WNE if it is available */
- if ( gHasWaitNextEvent ) {
- GetGlobalMouse(&mouse);
- /* AdjustCursor(mouse, gCursorRgn, (event.what == kHighLevelEvent)); */
- /* needed to remove MaxLong as the sleep value so help manager would get
- time to display balloons over the traffic light window
- */
- gotEvent = WaitNextEvent(everyEvent, &event, 30, gCursorRgn);
- }
- else {
- SystemTask();
- gotEvent = GetNextEvent(everyEvent, &event);
- }
- AdjustCursor(event.where, gCursorRgn, (event.what == kHighLevelEvent), *(long *) &event.where);
- if ( gotEvent ) {
- DoEvent(&event);
- }
- /* If you are using modeless dialogs that have editText items,
- you will want to call IsDialogEvent to give the caret a chance
- to blink, even if WNE/GNE returned FALSE. However, check FrontWindow
- for a non-NIL value before calling IsDialogEvent. */
- } while ( !gQuit );
- } /*EventLoop*/
-
-
- /* Do the right thing for an event. Determine what kind of event it is, and call
- the appropriate routines. */
-
- #pragma segment Main
- void DoEvent( EventRecord *event )
- {
- short part, err;
- WindowPtr window;
- char key;
- Point aPoint;
-
- switch ( event->what ) {
- case mouseDown:
- part = FindWindow(event->where, &window);
- switch ( part ) {
- case inMenuBar: /* process a mouse menu command (if any) */
- AdjustMenus();
- DoMenuCommand(MenuSelect(event->where));
- break;
- }
- break;
- case keyDown:
- case autoKey: /* check for menukey equivalents */
- key = event->message & charCodeMask;
- if ( event->modifiers & cmdKey ) /* Command key down */
- if ( event->what == keyDown ) {
- AdjustMenus(); /* enable/disable/check menu items properly */
- DoMenuCommand(MenuKey(key));
- }
- break;
- case activateEvt:
- DoActivate((WindowPtr) event->message, (event->modifiers & activeFlag) != 0);
- break;
- case updateEvt:
- DoUpdate((WindowPtr) event->message);
- break;
- /* 1.01 - It is not a bad idea to at least call DIBadMount in response
- to a diskEvt, so that the user can format a floppy. */
- case diskEvt:
- if ( HiWrd(event->message) != noErr ) {
- SetPt(&aPoint, kDILeft, kDITop);
- err = DIBadMount(aPoint, event->message);
- }
- break;
- case kOSEvent:
- /* 1.02 - must BitAND with 0x0FF to get only low byte */
- switch ((event->message >> 24) & 0x0FF) { /* high byte of message */
- case kSuspendResumeMessage: /* suspend/resume is also an activate/deactivate */
- gInBackground = (event->message & kResumeMask) == 0;
- DoActivate(FrontWindow(), !gInBackground);
- break;
-
- default:
- break;
- }
- break;
-
- case kHighLevelEvent:
- DoHighLevelEvent(event);
- break;
- }
- } /*DoEvent*/
-
-
- /* Change the cursor's shape, depending on its position. This also calculates
- the region where the current cursor resides (for WaitNextEvent). If the
- mouse is ever outside of that region, an event would be generated, causing
- this routine to be called, allowing us to change the region to the region
- the mouse is currently in. If there is more to the event than just “the
- mouse moved”, we get called before the event is processed to make sure the
- cursor is the right one. In any (ahem) event, this is called again before
- we fall back into WNE.
-
- Take special care on a kHighLevelEvent. Remember, event.where holds the
- class ID, not a mouse position!
- */
-
- #pragma segment Main
- void AdjustCursor( Point mouse, RgnHandle region, Boolean isAppleEvent, long classID )
- {
- WindowPtr window;
- RgnHandle arrowRgn;
- RgnHandle plusRgn;
- Rect globalPortRect;
- short cursorID;
-
- window = FrontWindow(); /* we only adjust the cursor when we are in front */
- if ( (! gInBackground) && (! IsDAWindow(window)) ) {
- if (isAppleEvent) {
- switch (classID) {
- case kAEOpenApplication: cursorID = oappCursor; break;
- case kAEOpenDocuments: cursorID = odocCursor; break;
- case kAEPrintDocuments: cursorID = pdocCursor; break;
- case kAEQuitApplication: cursorID = quitCursor; break;
- case kAEAnswer: cursorID = ansrCursor; break;
- case traeMoveFrontWindowMsgID: cursorID = mvfwCursor; break;
- case traeEchoID: cursorID = echoCursor; break;
- case 'wait': cursorID = watchCursor; break;
- }
- SetCursor(*GetCursor(cursorID));
- SetRectRgn(region, kExtremeNeg, kExtremeNeg, kExtremePos, kExtremePos);
- }
- else {
- /* calculate regions for different cursor shapes */
- arrowRgn = NewRgn();
- plusRgn = NewRgn();
-
- /* start with a big, big rectangular region */
- SetRectRgn(arrowRgn, kExtremeNeg, kExtremeNeg, kExtremePos, kExtremePos);
-
- /* calculate plusRgn */
- if ( IsAppWindow(window) ) {
- SetPort(window); /* make a global version of the viewRect */
- SetOrigin(-window->portBits.bounds.left, -window->portBits.bounds.top);
- globalPortRect = window->portRect;
- RectRgn(plusRgn, &globalPortRect);
- SectRgn(plusRgn, window->visRgn, plusRgn);
- SetOrigin(0, 0);
- }
-
- /* subtract other regions from arrowRgn */
- DiffRgn(arrowRgn, plusRgn, arrowRgn);
-
- /* change the cursor and the region parameter */
- if ( PtInRgn(mouse, plusRgn) ) {
- SetCursor(*GetCursor(plusCursor));
- CopyRgn(plusRgn, region);
- } else {
- SetCursor(&qd.arrow);
- CopyRgn(arrowRgn, region);
- }
-
- /* get rid of our local regions */
- DisposeRgn(arrowRgn);
- DisposeRgn(plusRgn);
- }
- }
- } /*AdjustCursor*/
-
-
- /* Get the global coordinates of the mouse. When you call OSEventAvail
- it will return either a pending event or a null event. In either case,
- the where field of the event record will contain the current position
- of the mouse in global coordinates and the modifiers field will reflect
- the current state of the modifiers. Another way to get the global
- coordinates is to call GetMouse and LocalToGlobal, but that requires
- being sure that thePort is set to a valid port. */
-
- #pragma segment Main
- void GetGlobalMouse( Point *mouse )
- {
- EventRecord event;
-
- OSEventAvail(kNoEvents, &event); /* we aren't interested in any events */
- *mouse = event.where; /* just the mouse position */
- } /*GetGlobalMouse*/
-
-
- /* This is called when an update event is received for a window.
- It calls DrawWindow to draw the contents of an application window.
- As an effeciency measure that does not have to be followed, it
- calls the drawing routine only if the visRgn is non-empty. This
- will handle situations where calculations for drawing or drawing
- itself is very time-consuming. */
-
- #pragma segment Main
- void DoUpdate( WindowPtr window )
- {
- if ( IsAppWindow(window) ) {
- BeginUpdate(window); /* this sets up the visRgn */
- if ( ! EmptyRgn(window->visRgn) ) { /* draw if updating needs to be done */
- SetPort(window);
- EraseRect(&window->portRect);
- DrawWindow(window);
- }
- EndUpdate(window);
- }
- } /*DoUpdate*/
-
-
- /* This is called when a window is activated or deactivated.
- In Sample, the Window Manager's handling of activate and
- deactivate events is sufficient. Other applications may have
- TextEdit records, controls, lists, etc., to activate/deactivate. */
-
- #pragma segment Main
- void DoActivate( WindowPtr window, Boolean becomingActive )
- {
- if ( IsAppWindow(window) ) {
- if ( becomingActive )
- /* do whatever you need to at activation */ ;
- else
- /* do whatever you need to at deactivation */ ;
- }
- } /*DoActivate*/
-
-
- /* This is called when a mouse-down event occurs in the content of a window.
- Other applications might want to call FindControl, TEClick, etc., to
- further process the click. */
-
- #pragma segment Main
- void DoContentClick( WindowPtr window )
- {
- SetLight(window, ! GetLight(window));
- } /*DoContentClick*/
-
-
- /* Draw the contents of the application window. We do some drawing in color, using
- Classic QuickDraw's color capabilities. This will be black and white on old
- machines, but color on color machines. At this point, the window’s visRgn
- is set to allow drawing only where it needs to be done. */
-
- #pragma segment Main
- void DrawWindow( GrafPtr window )
- {
- if ( GetLight(window) ) { /* draw a red (or white) stop light */
- ForeColor(redColor);
- PaintOval(&gStopRect);
- }
- ForeColor(blackColor);
- FrameOval(&gStopRect);
-
- if ( ! GetLight(window) ) { /* draw a green (or white) go light */
- ForeColor(greenColor);
- PaintOval(&gGoRect);
- }
- ForeColor(blackColor);
- FrameOval(&gGoRect);
-
- } /*DrawWindow*/
-
-
- /* Enable and disable menus based on the current state.
- The user can only select enabled menu items. We set up all the menu items
- before calling MenuSelect or MenuKey, since these are the only times that
- a menu item can be selected. Note that MenuSelect is also the only time
- the user will see menu items. This approach to deciding what enable/
- disable state a menu item has the advantage of concentrating all
- the decision-making in one routine, as opposed to being spread throughout
- the application. Other application designs may take a different approach
- that is just as valid. */
-
- #pragma segment Main
- void AdjustMenus()
- {
- WindowPtr window;
- MenuHandle menu;
-
- window = FrontWindow();
-
- menu = GetMHandle(mFile);
-
- EnableItem(menu, iNew);
- EnableItem(menu, iOpen);
- if ( !window ) {
- DisableItem(menu, iClose);
- DisableItem(menu, iSave);
- DisableItem(menu, iSaveAs);
- DisableItem(menu, iRevert);
- DisableItem(menu, iPageSetup);
- DisableItem(menu, iPrint);
- }
- else if ( IsDAWindow(window) ) { /* we can allow desk accessories to be closed from the menu */
- DisableItem(menu, iNew);
- DisableItem(menu, iOpen);
- DisableItem(menu, iSave);
- DisableItem(menu, iSaveAs);
- DisableItem(menu, iRevert);
- DisableItem(menu, iPageSetup);
- DisableItem(menu, iPrint);
- EnableItem(menu, iClose);
- }
- else {
- EnableItem(menu, iPageSetup);
- EnableItem(menu, iPrint);
- EnableItem(menu,iSave);
- EnableItem(menu, iClose); /* but not our traffic light window */
- }
-
- menu = GetMHandle(mEdit);
- if ( IsDAWindow(window) ) { /* a desk accessory might need the edit menu… */
- EnableItem(menu, iUndo);
- EnableItem(menu, iCut);
- EnableItem(menu, iCopy);
- EnableItem(menu, iClear);
- EnableItem(menu, iPaste);
- } else { /* …but we don’t use it */
- DisableItem(menu, iUndo);
- DisableItem(menu, iCut);
- DisableItem(menu, iCopy);
- DisableItem(menu, iClear);
- DisableItem(menu, iPaste);
- }
-
- menu = GetMHandle(mLight);
- if ( IsAppWindow(window) ) { /* we know that it must be the traffic light */
- EnableItem(menu, iStop);
- EnableItem(menu, iGo);
- if (window) {
- CheckItem(menu, iStop, GetLight(window)); /* we can also determine check/uncheck state, too */
- CheckItem(menu, iGo, !GetLight(window));
- } else {
- CheckItem(menu, iStop, false);
- CheckItem(menu, iGo, false);
- }
- } else {
- DisableItem(menu, iStop);
- DisableItem(menu, iGo);
- }
-
- menu = GetMHandle(mSendEvent);
- if (!gHasAppleEvents)
- DisableItem(menu, 0);
- else {
- EnableItem(menu, 0);
- if (!gHasPPCToolbox)
- DisableItem(menu, iChooseTarget);
- else {
- EnableItem(menu, iChooseTarget);
- CheckItem(menu, iChooseTarget, gSendToSelf);
- }
- DisableItem(menu, iSendClose);
- if (window)
- EnableItem(menu, iSendMove);
- else
- DisableItem(menu, iSendMove);
- EnableItem(menu, iSpeedTest);
- EnableItem(menu, iUseNoReply);
- EnableItem(menu, iUseWaitReply);
- EnableItem(menu, iUseQueueReply);
- CheckItem(menu, iUseNoReply, gReplyMode == kAENoReply);
- CheckItem(menu, iUseWaitReply, gReplyMode == kAEWaitReply);
- CheckItem(menu, iUseQueueReply, gReplyMode == kAEQueueReply);
- }
- } /*AdjustMenus*/
-
-
- /* This is called when an item is chosen from the menu bar (after calling
- MenuSelect or MenuKey). It performs the right operation for each command.
- It is good to have both the result of MenuSelect and MenuKey go to
- one routine like this to keep everything organized. */
-
- #pragma segment Main
- void DoMenuCommand( long menuResult )
- {
- short menuID; /* the resource ID of the selected menu */
- short menuItem; /* the item number of the selected menu */
- short itemHit;
- Str255 daName;
- short daRefNum;
- Boolean handledByDA;
- WindowPtr window;
- OSErr err;
-
- window = FrontWindow();
- menuID = HiWrd(menuResult); /* use macros for efficiency to... */
- menuItem = LoWrd(menuResult); /* get menu item number and menu number */
- switch ( menuID ) {
- case mApple:
- switch ( menuItem ) {
- case iAbout: /* bring up alert for About */
- itemHit = Alert(rAboutAlert, nil);
- break;
- default: /* all non-About items in this menu are DAs */
- GetItem(GetMHandle(mApple), menuItem, daName);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
- break;
- case mFile:
- switch ( menuItem ) {
- case iNew:
- err = OpenNewWindow();
- break;
- case iOpen:
- err = OpenFile(nil);
- break;
- case iSave:
- if ( window && SaveFile(window) ) {};
- break;
- case iClose:
- DoCloseWindow(window);
- break;
- case iPageSetup:
- PresentStyleDialog();
- break;
- case iPrint:
- err = StartPrintingProcess(true, &(window->portRect));
- break;
- case iQuit:
- Terminate();
- break;
- }
- break;
- case mEdit: /* call SystemEdit for DA editing & MultiFinder */
- handledByDA = SystemEdit(menuItem-1); /* since we don’t do any Editing */
- break;
- case mLight:
- switch ( menuItem ) {
- case iStop:
- SetLight(window, true);
- break;
- case iGo:
- SetLight(window, false);
- break;
- }
- break;
- case mSendEvent:
- switch ( menuItem ) {
- case iChooseTarget:
- gSendToSelf = !gSendToSelf;
- break;
- case iSendClose:
- break;
- case iSendMove:
- CreateAndSendAppleEvent(traeMoveFrontWindowMsgID);
- break;
- case iSpeedTest:
- CreateAndSendAppleEvent(traeEchoID);
- break;
- case iUseNoReply:
- gReplyMode = kAENoReply;
- break;
- case iUseWaitReply:
- gReplyMode = kAEWaitReply;
- break;
- case iUseQueueReply:
- gReplyMode = kAEQueueReply;
- break;
- }
- }
- HiliteMenu(0); /* unhighlight what MenuSelect (or MenuKey) hilited */
- } /*DoMenuCommand*/
-
-
- /* Change the setting of the light. */
-
- #pragma segment Main
- void SetLight( WindowPtr window, Boolean newStopped )
- {
- WindowDataHandle wData;
-
- if ( newStopped != GetLight(window) ) {
- wData = (WindowDataHandle) ((WindowPeek) window)->refCon;
- (**wData).stopped = newStopped;
- SetPort(window);
- InvalRect(&window->portRect);
- }
- } /*SetLight*/
-
-
- /* Return the setting of the light. */
-
- #pragma segment Main
- Boolean GetLight( WindowPtr window )
- {
- WindowDataHandle wData;
-
- if (window) {
- wData = (WindowDataHandle) ((WindowPeek) window)->refCon;
- return((**wData).stopped);
- }
- else
- return(false);
-
- } /*GetLight*/
-
-
- /* Close a window. This handles desk accessory and application windows. */
-
- /* 1.01 - At this point, if there was a document associated with a
- window, you could do any document saving processing if it is 'dirty'.
- DoCloseWindow would return true if the window actually closed, i.e.,
- the user didn’t cancel from a save dialog. This result is handy when
- the user quits an application, but then cancels the save of a document
- associated with a window. */
-
- #pragma segment Main
- Boolean DoCloseWindow( WindowPtr window )
- {
-
- if ( IsDAWindow(window) )
- CloseDeskAcc(((WindowPeek) window)->windowKind);
- else if ( IsAppWindow(window) ) {
- DisposHandle((Handle) ((WindowPeek) window)->refCon);
- DisposeWindow(window);
- }
-
- return true;
- } /*DoCloseWindow*/
-
-
- /* Clean up the application and exit. We close all of the windows so that
- they can update their documents, if any. */
-
- /* 1.01 - If we find out that a cancel has occurred, we won't exit to the
- shell, but will return instead. */
-
- #pragma segment Main
- void Terminate()
- {
- WindowPtr aWindow;
- Boolean closed;
-
- closed = true;
- do {
- aWindow = FrontWindow(); /* get the current front window */
- if (aWindow != nil)
- closed = DoCloseWindow(aWindow); /* close this window */
- }
- while (closed && (aWindow != nil));
- gQuit = true;
- } /*Terminate*/
-
-
- OSErr OpenOneWindow()
- {
- WindowPtr window;
- Handle data;
-
- window = (WindowPtr) NewPtr(sizeof(WindowRecord));
- if ( window == nil ) {
- DisplayError(0, nil, "Couldn't get a window record.");
- return(memFullErr);
- }
-
- window = GetNewWindow(rWindow, (Ptr) window, (WindowPtr) -1);
- if ( window == nil ) {
- DisplayError(0, nil, "Couldn't get a window from GetNewWindow.");
- return(memFullErr);
- }
-
- data = NewHandle(sizeof(WindowData));
- if ( data == nil ) {
- DisplayError(0, nil, "Couldn't get a window data handle.");
- return(memFullErr);
- }
-
- ((WindowPeek) window)->refCon = data;
- InstallGlobalWindowData(window);
-
- ShowWindow(window);
- SetPort(window);
-
- return(noErr);
- }
-
- OSErr OpenNewWindow()
- {
- SetInitialWindowState();
- return(OpenOneWindow());
- }
-
- void InstallGlobalWindowData(WindowPtr window)
- {
- Handle wData;
-
- if (window) {
- wData = (Handle) ((WindowPeek) window)->refCon;
- BlockMove((Ptr) &gWindowData, *wData, sizeof(WindowData));
- SetWTitle(window, gTitle);
- }
- }
-
- void ExtractWindowData(WindowPtr window)
- {
- Handle wData;
-
- if (window) {
- wData = (Handle) ((WindowPeek) window)->refCon;
- BlockMove(*wData, (Ptr) &gWindowData, sizeof(WindowData));
- }
- }
-
- void SetInitialWindowState(void)
- {
- gWindowData.stopped = true;
- GetIndString(gTitle, kMiscStrings, korigName); /* set default window title to untitled */
- }
-
- /* 1.01 - The code that used to be part of ForceEnvirons has been moved into
- this module. If an error is detected, instead of merely doing an ExitToShell,
- which leaves the user without much to go on, we call AlertUser, which puts
- up a simple alert that just says an error occurred and then calls ExitToShell.
- Since there is no other cleanup needed at this point if an error is detected,
- this form of error- handling is acceptable. If more sophisticated error recovery
- is needed, an exception mechanism, such as is provided by Signals, can be used. */
-
- #pragma segment Initialize
- void Initialize()
- {
- Handle menuBar;
- long total, contig;
- EventRecord event;
- short count;
-
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- for (count = 1; count <= 3; count++)
- EventAvail(everyEvent, &event);
-
-
- SysEnvirons(kSysEnvironsVersion, &gMac);
-
- if (gMac.machineType < 0) {
- DisplayError(0, nil, "Need a Mac Plus or better.");
- ExitToShell();
- }
-
- if (gMac.systemVersion < 0x0600) {
- DisplayError(0, nil, "Need System 6.0 or better.");
- ExitToShell();
- }
-
- gHasWaitNextEvent = TrapAvailable(_WaitNextEvent, ToolTrap);
- gHasNewStdFile = (gMac.systemVersion >= 0x0700);
-
- if ((long) GetApplLimit() - (long) ApplicZone() < kMinHeap) {
- DisplayError(0, nil, "Can't get enough heap space.");
- ExitToShell();
- }
-
- /* ZeroScrap(); */
-
- PurgeSpace(&total, &contig);
- if (total < kMinSpace) {
- DisplayError(0, nil, "Can't get enough free space.");
- ExitToShell();
- }
-
- InitAppleEvents();
-
- if ( !GoGetRect(rStopRect, &gStopRect) ) {
- DisplayError(0, nil, "Couldn't get Stop rect.");
- ExitToShell();
- }
- if ( !GoGetRect(rGoRect, &gGoRect) ) {
- DisplayError(0, nil, "Couldn't get Go rect.");
- ExitToShell();
- }
-
-
- } /*Initialize*/
-
-
- void StartDocuments()
- {
- OSErr err = noErr;
- short i;
- short whatToDo;
- short numberOfFiles;
- AppFile theAppFile;
- FSSpec fileSpec;
- long ignoredProcID;
-
- if (!gHasAppleEvents) {
- CountAppFiles(&whatToDo, &numberOfFiles);
- if (numberOfFiles > 0) {
- if (whatToDo == appPrint)
- PresentStyleDialog();
- for (i = 1; i <= numberOfFiles && !err; ++i) {
- GetAppFiles(i, &theAppFile);
- ClrAppFiles(i);
- err = GetWDInfo(theAppFile.vRefNum,
- &fileSpec.vRefNum,
- &fileSpec.parID,
- &ignoredProcID);
- if (err)
- DisplayError(err, nil, "StartDocuments: after GetWDInfo");
- else {
- BlockMove((Ptr) &theAppFile.fName, (Ptr) &fileSpec.name, theAppFile.fName[0] + 1);
- if (whatToDo == appOpen)
- err = OpenFile(&fileSpec);
- else if (whatToDo == appPrint)
- err = PrintFile(&fileSpec);
- else
- DisplayError(whatToDo, nil, "StartDocuments: got message from CountAppFiles I don't know what to do with.");
- } /* if (err) */
- } /* for... */
- if (whatToDo == appPrint)
- Terminate();
- } /* if (numberOfFiles) */
- else {
- err = OpenNewWindow();
- }
- }
- }
-
- /* This utility loads the global rectangles that are used by the window
- drawing routines. It shows how the resource manager can be used to hold
- values in a convenient manner. These values are then easily altered without
- having to re-compile the source code. In this particular case, we know
- that this routine is being called at initialization time. Therefore,
- if a failure occurs here, we will assume that the application is in such
- bad shape that we should just exit. Your error handling may differ, but
- the check should still be made. */
-
- #pragma segment Initialize
- Boolean GoGetRect( short rectID, Rect *theRect )
- {
- Handle resource;
-
- resource = GetResource('RECT', rectID);
- if ( resource != nil ) {
- *theRect = **((Rect**) resource);
- return true;
- }
- else
- return false;
- } /* GoGetRect */
-
-
- #pragma segment Main
- Boolean IsAppWindow( WindowPtr window )
- {
- short windowKind;
-
- if ( window == nil )
- return false;
- else { /* application windows have windowKinds = userKind (8) */
- windowKind = ((WindowPeek) window)->windowKind;
- return (windowKind = userKind);
- }
- } /*IsAppWindow*/
-
-
- /* Check to see if a window belongs to a desk accessory. */
-
- #pragma segment Main
- Boolean IsDAWindow( WindowPtr window )
- {
- if ( window == nil )
- return false;
- else /* DA windows have negative windowKinds */
- return ((WindowPeek) window)->windowKind < 0;
- } /*IsDAWindow*/
-
-
- /* Check to see if a given trap is implemented. This is only used by the
- Initialize routine in this program, so we put it in the Initialize segment.
- The recommended approach to see if a trap is implemented is to see if
- the address of the trap routine is the same as the address of the
- Unimplemented trap. */
- /* 1.02 - Needs to be called after call to SysEnvirons so that it can check
- if a ToolTrap is out of range of a pre-MacII ROM. */
-
- #pragma segment Initialize
- Boolean TrapAvailable( short tNumber, TrapType tType )
- {
- if ( ( tType == ToolTrap ) &&
- ( gMac.machineType > envMachUnknown ) &&
- ( gMac.machineType < envMacII ) ) { /* it's a 512KE, Plus, or SE */
- tNumber = tNumber & 0x03FF;
- if ( tNumber > 0x01FF ) /* which means the tool traps */
- tNumber = _Unimplemented; /* only go to 0x01FF */
- }
- return NGetTrapAddress(tNumber, tType) != GetTrapAddress(_Unimplemented);
- } /*TrapAvailable*/
-
-
- /* Display an alert that tells the user an error occurred, then exit the program.
- This routine is used as an ultimate bail-out for serious errors that prohibit
- the continuation of the application. Errors that do not require the termination
- of the application should be handled in a different manner. Error checking and
- reporting has a place even in the simplest application. The error number is used
- to index an 'STR#' resource so that a relevant message can be displayed. */
-
- #pragma segment Main
- void AlertUser()
- {
- short itemHit;
-
- SetCursor(&qd.arrow);
- itemHit = Alert(rUserAlert, nil);
- ExitToShell();
- } /* AlertUser */
-
-
-
-
-
-
-
-
-
-